// pages/search/search.js
const {post } = require('../../utils/http')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    keyword:'',
    datalist:[],
    historylist:wx.getStorageSync('historylist')||[],
    showhistory:true
  },
  inpuntChange(e){
      this.setData({
    keyword:e.detail.value
  })
},
async handleSearch(){
  let historylist= wx.getStorageSync('historylist')||[];
  historylist.push(this.data.keyword);

  let list = [...new Set(historylist)];
  console.log([...new Set(historylist)]);

  wx.setStorageSync('historylist', list)

   let result = await post('/index.php/trade/get_search_list',{keyword:this.data.keyword})
  this.setData({
    datalist:result.data,
    showhistory:false
  })
}
,
searchByhistory(e){
  console.log(e)
  this.setData({
    keyword:e.currentTarget.dataset.keyword
  })
  this.handleSearch()
},
goDetail(e){
  let id = e.currentTarget.dataset.id;
  wx.navigateTo({
    url: '/pages/detail/detail?id='+id,
  })
}


})